<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Post>>" %>

<%@ Import Namespace="DNA.Mvc.Areas.Community.Controllers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% var threadPost = (Post)ViewData["ThreadPost"];
       if (!threadPost.ThreadReference.IsLoaded) threadPost.ThreadReference.Load();
       var thread = threadPost.Thread;
       if (!thread.ForumReference.IsLoaded) thread.ForumReference.Load();
    %>
    <div style="margin-bottom: 5px; height: 30px;">
        <%:Ajax.ForumMapPath(thread.Forum.ID)%>
    </div>
    <div style="clear: left;">
    </div>
    <% Html.RenderAction("Detail", "Forum", new { id = threadPost.Forum.ID }); %>
    <% if (Request.IsAuthenticated)
       { %>
    <div style="display: inline-block; margin-bottom: 10px;">
        <% if (Html.IsAuthorize<PostController>("New"))
           {
               if ((thread.Forum.IsModerator()) || (!thread.Forum.IsLock))
               {
        %>
        <%:Ajax.jQueryActionLink(Html.Global("forums", "NewThread"), "ui-icon ui-icon-lightbulb", "New", "Post", new { Area = "Community", forumID = threadPost.Forum.ID })%>
        <%}
           } %>
        <%
            if (thread.IsAppoved)
            {
                if (!thread.IsLocked)
                {
                    if (Html.IsAuthorize<PostController>("Lock") || threadPost.IsModerator())
                    {
        %>
        <%=Ajax.jQueryActionLink(Html.Global("forums", "Lock"), "ui-icon ui-icon-locked", "Lock", "Post", new { id = thread.ID })%>
        <%}
                }
                else
                {
                    if (Html.IsAuthorize<PostController>("Unlock") || threadPost.IsModerator())
                    {
        %>
        <%=Ajax.jQueryActionLink(Html.Global("forums", "Unlock"), "ui-icon ui-icon-unlocked", "Unlock", "Post", new { id = thread.ID })%>
        <%}
                }%>
        <% if (!thread.IsPinned)
           {
               if (Html.IsAuthorize<PostController>("Pin") || threadPost.IsModerator())
               {
        %>
        <%=Ajax.jQueryActionLink(Html.Global("forums", "Pin"), "ui-icon ui-icon-pin-w", "Pin", "Post", new { id = thread.ID })%>
        <%}
           }
           else
           {
               if (Html.IsAuthorize<PostController>("Unpin") || threadPost.IsModerator())
               {
        %>
        <%=Ajax.jQueryActionLink(Html.Global("forums", "Unpinned"), "ui-icon ui-icon-pin-s", "Unpin", "Post", new { id = thread.ID })%>
        <%}
           }
           if (Html.IsAuthorize<PostController>("Move") || threadPost.IsModerator())
           {
        %>
        <%=Ajax.jQueryActionLink(Html.Global("forums", "Move"), "ui-icon ui-icon-copy", "Move", "Post", new { id = thread.ID })%>
        <%}
            }%>
    </div>
    <%} %>
    <div class="ui-widget-content ui-corner-top" style="margin:5px;">
        <div class="ui-widget-header ui-corner-top ui-border-bottom" style="padding-left: 10px;
            overflow: auto;">
            <h2 id="topPost">
                <%=threadPost.Title%><% if (!thread.IsAppoved)
                                        { %>
                : waiting for audit<%} %>
            </h2>
        </div>
        <table style="width: 100%; border: none;" cellpadding="5" cellspacing="1" class="ui-post-list">
            <% foreach (var post in Model)
               {
                   if ((post.IsAppoved) || (post.IsModerator()) || post.IsOwner())
                   {
            %>
            <tr>
                <td style="width: 200px; position: relative;" class="ui-widget-content" valign="top">
                    <% Html.RenderPartial("UserInfo", post.UserProfile); %>
                </td>
                <td valign="top">
                    <div class="ui-state-active" style="padding: 10px; display: block; height: 17px;
                        position: relative;">
                        <div style="float: left; display: inline-block">
                            <strong id="<%:post.ID.ToString() %>">#<%=post.Pos%></strong>&nbsp;:&nbsp;<%:Html.Global(post.Posted)%>
                        </div>
                        <% if (!post.IsDeleted)
                           {%>
                        <div style="float: right; display: inline-block; position: absolute; top: 2px; right: 0px;">
                            <%if (!post.IsAppoved)
                              {
                                  if ((post.IsModerator()) || (Html.IsAuthorize<PostController>("Audit")))
                                  {%>
                            <%=Ajax.jQueryActionLink(Html.Global("forums", "Audit"), "ui-icon ui-icon-clock", "Audit", "Post", new { id = post.ID })%>
                            <%}
                              } %>
                            <% if (Html.IsAuthorize<PostController>("Edit"))
                               {
                                   if ((post.IsOwner()) || (post.IsModerator()))
                                   { 
                            %>
                            <%=Ajax.jQueryActionLink(Html.Global("forums", "Edit"), "ui-icon ui-icon-pencil", "Edit", "Post", new { id = post.ID })%>
                            <%}
                               }
                               if (Html.IsAuthorize<PostController>("Delete"))
                               {
                                   if ((post.IsOwner()) || (post.IsModerator()))
                                   {
                            %>
                            <%:Ajax.jQueryActionLink(Html.Global("forums", "Delete"), "ui-icon ui-icon-close", "Delete", "Post", new { id = post.ID })%>
                            <%
                                }
                               }
                               if ((!thread.IsLocked) && (thread.IsAppoved))
                               {
                                   if ((post.IsOwner()) || (post.IsModerator()) || (Html.IsAuthorize<PostController>("Reply")))
                                   {%>
                            <%=Ajax.jQueryActionLink(Html.Global("forums", "Reply"), "ui-icon ui-icon-script", "Reply", "Post", new { id = threadPost.ID, parentID = post.ID })%>
                            <%}

                                   if ((post.IsOwner()) || (post.IsModerator()) || (Html.IsAuthorize<PostController>("Quote")))
                                   {%>
                            <%=Ajax.jQueryActionLink(Html.Global("forums", "Quote"), "ui-icon ui-icon-comment", "Quote", "Post", new { id = threadPost.ID, quoteID = post.ID })%>
                            <%}
                               }%>
                        </div>
                        <%} %>
                    </div>
                    <div style="padding: 5px; margin-top: 5px; min-height: 200px;">
                        <% if ((!post.IsAppoved) && (post.IsOwner()))
                           { %>
                        <div class="ui-state-highlight" style="padding: 5px; margin: 5px;">
                            Your post is wait for audit.It will not be display before moderator audit.</div>
                        <%} %>
                        <% if (!post.IsDeleted)
                           {
                        %>
                        <%:Html.FormatXhtml(Html.FormatBBCode(post.Body).ToString())%>
                        <%
                            }
                           else
                           { 
                        %>
                        <div class="ui-state-error" style="margin: 5px; padding: 5px;">
                            This post was deleted by
                            <%: post.DeleteBy%>
                            at
                            <%:Html.Global(post.Deleted.Value)%>
                            <%:"because " + post.DeletedReason%>
                        </div>
                        <%} %>
                    </div>
                    <% if (post.HasAttachment)
                       { %>
                    <% if (HttpContext.Current.Request.IsAuthenticated)
                       { %>
                    <div style="margin-top: 10px; margin-bottom: 10px;">
                        <div>
                            <b>Attachments:</b></div>
                        <% Html.RenderPartial("Attachments", post.Attachments); %>
                    </div>
                    <%}
                       else
                       { %>
                    <div class="ui-state-highlight">
                        You could not see this attachments before you
                        <%:Html.ActionLink("login", "LogOn", "Account", new { Area = "" }, null)%>
                    </div>
                    <%}
                       } %>
                    <% if (!string.IsNullOrEmpty(post.UserProfile["Signature"].ToString()))
                       {  %>
                    <div class="ui-widget-content" style="padding: 0px; background: none; border-top: none;
                        border-left: none; border-right: none;">
                    </div>
                    <div style="padding-top:5px;padding-bottom:5px;">
                        <%:Html.FormatXhtml(Html.FormatBBCode(post.UserProfile["Signature"].ToString()).ToString())%>
                    </div>
                    <%} %>
                </td>
            </tr>
            <tr>
                <td class="ui-state-highlight">
                    <a href="#topPost"><span style="float: left;" class="ui-icon ui-icon-triangle-1-n"></span>
                        <%=Html.Global("forums", "BackToTop")%></a>
                </td>
                <td class="ui-state-highlight" align="right">
                    <% if ((Request.IsAuthenticated) && (User.IsInRole("administrators")))
                       { %>
                    IP:<%=post.IP %>
                    <%}
                       else
                       {%>
                    IP:******
                    <%} %>
                </td>
            </tr>
            <%}
               } %>
        </table>
    </div>
    <% if (((int)ViewData["TotalRecords"]) > 10)
       { %>
    <%=Ajax.Pager("ThreadPager", new PagerOptions() { PageIndex = (int)ViewData["PageIndex"], PageSize = (int)ViewData["PageSize"], TotalRecords = (int)ViewData["TotalRecords"], OnPageIndexChanged = "window.location='" + Url.Action("Thread", new { id = threadPost.Thread.ID }) + "?index='+ui.pageIndex+'&size='+ui.pagesize;" }, null)%>
    <%} %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <%=Html.CssLink("~/Content/forums.css")%>
</asp:Content>
